﻿using MediatR;
using S.Eartag.Domain.Model;
using S.Eartag.Infrastructure.Interface;
using S.Eartag.Read.API.Application.Command.SheepFileConditionCommand;

namespace S.Eartag.Read.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionFindsCommandHanler : IRequestHandler<SheepFileConditionFindsCommand, SheepFile>
    {

        private readonly ISheepFileRepository sheepFileRepository;

        public SheepFileConditionFindsCommandHanler(ISheepFileRepository sheepFileRepository)
        {
            this.sheepFileRepository = sheepFileRepository;
        }

        public async Task<SheepFile> Handle(SheepFileConditionFindsCommand request, CancellationToken cancellationToken)
        {
            var res = await sheepFileRepository.GetValues(x => x.EarNumber == request.card);           
            return  res.FirstOrDefault();
        }
    }
}
